# status_tab.pl
# function for tabform

# load modules
require "./electric_bulletin_board-lib.pl";
require "./config.pl";


# status_tab()
# status tab generate functions
sub status_tab() {
	# configure form start
	print &ui_form_start("index.cgi", "get");
	
	# tab name
	print &ui_hidden("tab", "status");
	
	# table start
	@tds = ("width=20%", "width=40%");
	@bgcolor = ("bgcolor=\"#c6deea\"", "bgcolor=\"#a7f3cf\"");
	print &item_br();
	print &ui_columns_start(undef, 100, 1, \@tds);
	
	# now status row 
	my $now_status;
	if (-e $lockfile) {
		$now_status = "表示中";
	} else {
		$now_status = "停止中";
	}
	print &ui_columns_row(["ステータス", $now_status], \@bgcolor);
	
	# show pattern name row
	print &ui_columns_row(["表示パターン名", "パターン０１"], \@bgcolor);
	
	# set pattern date row
	my $create_time = &serial2time((stat("$module_root_directory/pattern/group.list"))[9], 1);
	print &ui_columns_row(["パターン設定日", $create_time], \@bgcolor);
	
	# pattern preview row
	print &ui_columns_row(["パターンプレビュー", "<img src=images/icon.gif>"], \@bgcolor);
	
	# table end
	print &ui_columns_end();
	
	# select start and stop
	print &item_br();
	my $now_status;
	if (-e $lockfile) {
		$now_status = "ON";
	} else {
		$now_status = "OFF";
	}
	
	@radio_array = (["ON", "起動"], ["OFF", "停止"]);
	print &ui_radio("change_status", $now_status, \@radio_array);
	
	# run button
	print &item_hr();
	print &ui_submit($text{'status_submit'});
	
	# configure form end
	print &ui_form_end();
}

# status_run()
# status run functions
sub status_run() {
	# start and stop
	if ($in{'change_status'} eq "ON") {
		# --- Debug Code Start -----------------------------------------------------
		system("touch $lockfile");
		system("./send.pl /dev/ttyUSB0 $module_root_directory/pattern/group.list $lockfile &");
		# --- Debug Code End -------------------------------------------------------
	} elsif ($in{'change_status'} eq "OFF") {
		&unlink_file("$lockfile");
	}
	
	return;
}

